#ifndef TEST_H_
#define TEST_H_

#include "DataType.h"
#include "h1010.h"
#include "SI.h"
#include "main.h"

#define ENABLE_DEBUG_SERIAL 0
#define TARGET_SPX_1_EXP_0 1

#if ENABLE_DEBUG_SERIAL
#define SERIAL_OVER_UART 0

#define ENABLE_DEBUG_SERIAL_UART 1

#define DEBUG_SERIAL_SI 1
#define DEBUG_SERIAL_SO 0

#endif

#if TARGET_SPX_1_EXP_0
#define TEST_PIN_PORT	GPIO_PORT_P8
#define TEST_PIN_PORT2	GPIO_PORT_P8
#define TEST_PIN_PORT3	GPIO_PORT_P8
#define TEST_PIN_PORT4	GPIO_PORT_P8
#define TEST_PIN		GPIO_PIN6
#define TEST_PIN2		GPIO_PIN4
#define TEST_PIN3		GPIO_PIN2
#define TEST_PIN4		GPIO_PIN0
#else
#define TEST_PIN_PORT	GPIO_PORT_P10
#define TEST_PIN_PORT2	GPIO_PORT_P10
#define TEST_PIN_PORT3	GPIO_PORT_P10
#define TEST_PIN_PORT4	GPIO_PORT_P10
#define TEST_PIN		GPIO_PIN0
#define TEST_PIN2		GPIO_PIN1
#define TEST_PIN3		GPIO_PIN2
#define TEST_PIN4		GPIO_PIN3
#endif
#define GPIO_ALL			(GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7)
#define TEST_ADC_PROCESS 	GPIO_PIN0
#define TEST_ADC_CAPTURE 	GPIO_PIN2
#define TEST_LED_THREAD 	GPIO_PIN4
#define TEST_25ms_ISR 		GPIO_PIN6
#define TEST_SPIDER_WEB 	GPIO_PIN7
#define TEST_SI_1_ALM 		GPIO_PIN5
#define TEST_SO_1_ON 		GPIO_PIN3
#define TEST_SI_1_FLT		GPIO_PIN1

enum DebugCmd {
	DebugCmd_init=0,
	Debug=1,
	DebugCmd_ledError=2,
	Debug_i2cError=3,
	Debug_siError=4,
	Debug_tbd1=5,
	Debug_tbd2=6,
	Debug_tbd3=7,
	Debug_tbd4=8,
	Debug_tbd5=9,
	Debug_tbd6=10,
	Debug_tbd7=11,
	Debug_tbd8=12,
	Debug_tbd9=13,
	Debug_tbd10=14,
	Debug_tbd11=15,
	DebugCmd_SI_1=65,
	DebugCmd_SI_2=66,
	DebugCmd_SI_3=67,
	DebugCmd_SI_4=68,
	DebugCmd_SI_5=69,
	DebugCmd_SI_6=70,
	DebugCmd_SI_7=71,
	DebugCmd_SI_8=72,
	DebugCmd_SO_1=73,
	DebugCmd_letterA=65,
	DebugCmd_letterB=66,
	DebugCmd_letterC=67,
	DebugCmd_letterD=68,
	DebugCmd_letterE=69,
	DebugCmd_letterF=70,
	DebugCmd_letterG=71,
	DebugCmd_letterH=72
};
enum DebugStatus {
	DEBUG_DISABLED=0,
	DEBUG_ENABLED=1
};
void Test_christmasTree(void);
void I2CioDriver_test_thread(void);
void I2CioDriver_test (void);
int  Test_Serial_init(void);
void Test_Serial_sendCmdAndByte(enum DebugCmd cmd, unsigned char byte);
void Test_Serial_sendCmdAndData(enum DebugCmd cmd, unsigned char * data, unsigned int numBytes);
void Test_Serial_sendMsg(enum DebugCmd cmd, unsigned char numBytes);
enum DebugStatus Test_Serial_getDebugStatus(void);
void Test_Serial_toggleDebugStatus(void);
void Test_Serial_msgReset(void);
int Test_Serial_msgAppend(unsigned char * _msg, unsigned int numBytes, unsigned char offset);

void I2C_SO_test_driver(const struct configMemRAM_t * pConfigMemRAM);
RTN_TYPE loadInhibitedSettings(const struct configMemRAM_t * pConfigMemRAM);
void test_SOfault(const struct configMemRAM_t * pConfigMemRAM);
void test_miscFaults(const struct configMemRAM_t * pConfigMemRAM);
void test_fltAlmRelays(const struct configMemRAM_t * pConfigMemRAM);
void test_harness(const struct configMemRAM_t * pConfigMemRAM);
void test_loadTestConfig(const struct configMemRAM_t * pConfigMemRAM, enum SI_X siMe);

void testPinPort8_init(unsigned char _mask);
void testPinPort8_on(unsigned char _mask);
void testPinPort8_off(unsigned char _mask);
void test_testPin_init(void);
void test_testPin_On(void);
void test_testPin_Off(void);
void test_testPin_toggle(void);
void test_testPin2_init(void);
void test_testPin2_On(void);
void test_testPin2_Off(void);
void test_testPin3_init(void);
void test_testPin3_On(void);
void test_testPin3_Off(void);
void test_testPin4_init(void);
void test_testPin4_On(void);
void test_testPin4_Off(void);

void SI_test_SH_nonLatchNoTimer(BYTE useTestConfig);
void SI_test_SH_centCfg(BYTE useTestConfig);
void SI_test_SH_centCfgSZ2x(BYTE useTestConfig);
void SI_test_SI8almEntry_overrideAdcState(void);
void SI_test_thread(void);
void SI_test_SI1almEntry_overrideAdcState(void);
void SI_test_SI8nonShortingSM_overrideAdcState(void);

void Test_REL_resourceArray_requestRelay_requestTwice(void);

void Test_testHarness (void);

#endif /* TEST_H_ */
